//
//  EruptDTO.m
//  FastDoctor
//
//  Created by 李通 on 16/7/8.
//  Copyright © 2016年 sc. All rights reserved.
//

#import "EruptDTO.h"

@implementation EruptDTO

+ (instancetype)modelWithDict:(NSDictionary *)dict {
    
    EruptDTO *eruptModel = [[EruptDTO alloc]init];
    
    [eruptModel setValuesForKeysWithDictionary:dict];
    
    return eruptModel;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
    
}

+ (void)getEruptListSuccess:(void (^)(NSArray<EruptDTO *> *))successBlock error:(void (^)())errorBlock {
    
    [SVProgressHUD show];
    NSDictionary *paramDic = @{@"page":@1,@"page_size":@15,@"ci2_id":@3
                               };
    
    [[NetWorkTool sharedWorkTool]POST:kComplicationListUrl parameters:paramDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSArray *array = responseObject[@"data"];
        
        NSMutableArray *totalArray = [NSMutableArray array];
        [totalArray addObjectsFromArray:array];
        
        [self getArrayWith:array andNum:2 andTotalArray:totalArray];
        [self getArrayWith:array andNum:3 andTotalArray:totalArray];
        
    NSMutableArray *mArray = [NSMutableArray array];
        
       
            
            [totalArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                EruptDTO *eruptModel = [EruptDTO modelWithDict:obj];
                [mArray addObject:eruptModel];
            }];

        if (successBlock) {
            
            successBlock(mArray.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (errorBlock) {
            errorBlock();
        }
    }];
}


+(void)getArrayWith:(NSArray *)array andNum:(int)num andTotalArray :(NSMutableArray*)totalArray{
    [array enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@%d",obj[@"complication_name"],num] forKey:@"complication_name"];
        [totalArray addObject:dict];
        
    }];
}

@end
